package com.supinfo.food.services;

import java.util.List;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;

import com.supinfo.food.dao.DaoFactory;
import com.supinfo.food.dao.TableDao;
import com.supinfo.food.entities.TableRestaurant;

/**
 * Table service
 * @author Keitaro
 */
@WebService(name="Table", serviceName="Table")
public class TableService {

	private TableDao dao = DaoFactory.getTableDao();
	
	@WebMethod(operationName="add")
	public boolean	add(@WebParam(name="magasin") TableRestaurant table) {
		List<TableRestaurant> list = dao.getByMagasin(table.getMagasin().getId());
		for (TableRestaurant obj : list)
			if (obj.getNumero().equals(table.getNumero()))
				return false;
		dao.persist(table);
		return true;
	}
	
	@WebMethod(operationName="delete")
	public void	delete(Long id) {
		dao.remove(id);
	}
	
	@WebMethod(operationName="getByMagasin")
	public TableRestaurant[]	getByMagasin(Long id) {
		List<TableRestaurant> list = dao.getByMagasin(id);
		if (list == null || list.isEmpty())
			return null;
		return list.toArray(new TableRestaurant[1]);
	}
}
